package com.onpositive.page.pagerendering;

import java.util.Map;

import com.onpositive.storage.managers.ProfilesUsersManager;

public class UserProfilePageRenderer {

	public String getContent(String nickName, String message) {
		StringBuilder sb = new StringBuilder();
		sb.append("== Users parameters for Update site ==\n");
		sb.append(message + "\n");		
		sb.append("{{{\n");
		sb.append("#!html\n");
		sb.append("<form action=\"profile.page\" method=\"post\" >\n");
		sb.append("<table>\n");
		Map<String, Object> params = ProfilesUsersManager
				.getUsersPref(nickName);

		String s = ProfilesUsersManager.NICK_PROP;
		for (int i = 0; i < 2; i++) {
			sb.append("<tr>\n");
			if (ProfilesUsersManager.PARAMS_TYPES.get(s).equals(String.class)) {
				String val = "";
				if (params != null) {
					val = (String) params.get(s);
					if (val == null) {
						val = "";
					}
					if (s.equals(ProfilesUsersManager.NICK_PROP)) {
						val = nickName;
					}
				} else {
					if (s.equals(ProfilesUsersManager.NICK_PROP)) {
						val = nickName;
					}
				}
				sb.append("<td>\n");
				sb.append(s + "");
				sb.append("</td>\n");
				sb.append("<td>\n");
				sb.append("<input type=\"text\" name=\"" + s + "\" value =\""
						+ val + "\">\n");
				sb.append("</td>\n");
			}
			s = ProfilesUsersManager.UPDS_PASS_PROP;
			sb.append("</tr>");
		}
		sb.append("<tr>\n");
		sb.append("<td>\n");
		sb.append("<br>\n");
		sb.append("<input type=\"submit\" value=\"save\">\n");
		sb.append("</td>\n");
		sb.append("</tr>");
		sb.append("</table>\n");
		sb.append("</form>\n");
		sb.append("}}}\n");

		return sb.toString();
	}

}
